package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自媒体用户信息表 前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/user/")
public class WmUserController {

    @Autowired
    private WmUserService wmUserService;

    /**
     * 根据用户名查自媒体用户
     *
     * @param name
     * @return
     */
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {
        return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
    }

    /**
     * 保存自媒体用户
     *
     * @param wmUser
     * @return
     */
    @PostMapping("/save")
    public WmUser save(@RequestBody WmUser wmUser) {
        wmUserService.save(wmUser);
        return wmUser;
    }

    /**
     * 根据自媒体用户id查询wm_user
     * @param id
     * @return
     */
    @GetMapping("findOne/{id}")
    public WmUser findById(@PathVariable("id") Integer id) {
        return wmUserService.getById(id);
    }
}
